#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>

typedef struct dancer
{
	char name[20];
	char sex;
}dan;
struct node
{
	dan* d;
	int f;
	int r;
};
#define MAX 10
struct node* queueInit()
{
	struct node* p = (struct node*)malloc(sizeof(struct node));
	if (p == NULL)
		return p;
	p->d = (dan*)malloc(sizeof(dan));
	if (p->d == NULL)
	{
		free(p);
		return NULL;
	}
	p->f = p->r = 0;
	return p;
}
bool is_empty(struct node* p)
{
	if (p->f == p->r)
		return true;
	else
		return false;
}
bool is_full(struct node* p)
{
	if (p->f == ((p->r + 1) % MAX))
		return true;
	else
		return false;
}
bool en_queue(struct node* p, dan data)
{
	if (is_full(p))
		return false;
	p->d[p->r] = data;
	p->r = (p->r + 1) % MAX;
	return true;
}
bool out_queue(struct node* p, dan* val)
{
	if (is_empty(p))
		return false;
	*val = p->d[p->f];
	p->f = (p->f + 1) % MAX;
	return true;
}
bool get_head(struct node* p, dan* val)
{
	if (is_empty(p))
		return false;
	*val = p->d[p->f];
	return true;
}
void show(struct node* p)
{
	if (is_empty(p))
		return;
	int i = p->f;
	while (i != p->r)
	{
		printf("%s %c", p->d[i].name, p->d[i].sex);
		i = (i + 1) % MAX;
	}
	printf("\n");
}
void match(dan* dancer, int num)
{
	struct node* mq = queueInit();
	struct node* fq = queueInit();
	dan d;
	int i = 0;
	for (i = 0; i < num; i++)
	{
		d = dancer[i];
		if (d.sex == 'f')
		{
			en_queue(fq, d);
		}
		else
		{
			en_queue(mq, d);
		}
	}
	while (!is_empty(fq) && !is_empty(mq))
	{
		out_queue(fq, &d);
		printf("%s\t", d.name);
		out_queue(mq, &d);
		printf("%s\t\n", d.name);
	}
	if (!is_empty(fq))
	{
		get_head(fq, &d);
		printf("%s\n", d.name);
	}
	if (!is_empty(mq))
	{
		get_head(mq, &d);
		printf("%s\n", d.name);
	}
}
int main()
{
	dan dancer[5];
	int i = 0;
	for (i = 0; i < 5; i++)
	{
		printf("shuru di %d wei \n", i);
		scanf("%s %c", dancer[i].name, &(dancer[i].sex));
		getchar();
	}
	match(dancer, 5);
	return 0;
}